package com.slipper.system.dictionary.front;

import com.slipper.common.bo.Result;
import com.slipper.common.util.DicUtil;
import com.slipper.system.dictionary.service.DictionaryService;

import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

import com.slipper.common.util.ResultUtil;
import com.slipper.system.api.dictionary.bo.DictionaryBO;
import com.slipper.system.api.dictionary.service.IDictionarySv;

import java.util.List;
import java.util.Map;

@RestController
public class DictionarySv implements IDictionarySv {
    @Resource
    private DictionaryService dictionaryService;
    
    @Override
    public Result<DictionaryBO> queryBy(DictionaryBO bo){
        return ResultUtil.successResult(dictionaryService.queryBy(bo.getId()));
    }
    
    @Override
    public Result<List<DictionaryBO>> queryPage(DictionaryBO bo){
        return ResultUtil.successResult(dictionaryService.queryPage(bo));
    }
    
    @Override
    public Result<?> save(DictionaryBO bo){
        int result = this.dictionaryService.save(bo);
        DicUtil.clearCache();
        return ResultUtil.successResult(result);
    }
    
    @Override
    public Result<?> delete(DictionaryBO bo){
        int result = dictionaryService.delete(bo);
        DicUtil.clearCache();
        return ResultUtil.successResult(result);
    }
    
    @Override
    public Result<List<Map<String, String>>> queryDicData(String dicCode) {
        return ResultUtil.successResult(this.dictionaryService.queryDicData(dicCode));
    }

    @Override
    public Result<Map<String, List<Map<String, String>>>> queryAllDicData() {
        return ResultUtil.successResult(DicUtil.getAllDicData());
    }

    @Override
    public Result<List<DictionaryBO>> queryList(DictionaryBO bo) {
        return ResultUtil.successResult(this.dictionaryService.queryList(bo));
    }

    @Override
    public Result<Map<String, String>> querySingleDicData(String dicCode) {
        return ResultUtil.successResult(DicUtil.getDicData(dicCode));
    }
}
